from typing import List


def list_inner_dict_distinct(_items: List[dict], _distinct_key_set: set) -> List[dict]:
    new_items = []
    new_key_list = []
    for item in _items:
        if type(item) != dict:
            continue
        _keys = item.keys()
        if _distinct_key_set.issubset(_keys):
            distinct_key = "-".join([str(item[key]) for key in _distinct_key_set])
            if distinct_key in new_key_list:
                continue
            else:
                new_key_list.append(distinct_key)
                new_items.append(item)
        else:
            s = f"去重集合: {_distinct_key_set}, 不是 字典集合: {_keys} 的子集 "
            print(s)
            raise Exception(s)

    return new_items


def order_dict_by_list(_items: List[dict], _order_list: list, _order_key: str):
    new_items = []
    for curr_order in _order_list:
        curr_item_list = [item for item in _items if item[_order_key] == curr_order]
        new_items.extend(curr_item_list)
    return new_items


def order_list_by_list(_item: list, _order_list: list):
    new_item = []
    for curr_order in _order_list:
        curr_item_list = [item for item in _item if item == curr_order]
        new_item.extend(curr_item_list)
    return new_item


if __name__ == "__main__":
    items = [
        {"a": 2, "b": 2},
        {"a": 3, "b": 2},
        {"a": 1, "b": 2}
    ]
    order_list = [3, 1, 2]
    by_list = order_dict_by_list(items, order_list, "a")
    print(by_list)
    items2 = [2, 2, 3, 3, 1]
    by_list2 = order_list_by_list(items2, order_list)
    print(by_list2)
